package com.afs.electronicforensics.utils;

import android.app.Activity;
import android.app.AlertDialog;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;


import com.afs.electronicforensics.activity.R;


public class CreateDialog {

    private static AlertDialog.Builder builder;//弹框
    private static AlertDialog dialog;
    private static LayoutInflater inflater;//获取dialog.xml中的三个TextView

    public static void createAvatarDialog(Activity activity){
        builder = new AlertDialog.Builder(activity);//创建对话框
        inflater = activity.getLayoutInflater();
        View layout = inflater.inflate(R.layout.avatar_dialog, null);//获取自定义布局
        builder.setView(layout);//设置对话框的布局
        AlertDialog dialog = builder.create();//生成最终的对话框
        dialog.show();//显示对话框

        TextView takePhoto = layout.findViewById(R.id.photograph);
        TextView choicePhoto = layout.findViewById(R.id.photo);
        TextView cancel = layout.findViewById(R.id.cl);

        takePhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MediaUtil.openCameraForImage(activity);
                MediaUtil.imageFlag = false;
                dialog.dismiss();
            }
        });
        choicePhoto.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MediaUtil.pickImageFromSystem(activity);
                MediaUtil.imageFlag = false;
                dialog.dismiss();
            }
        });
        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });
    }

    public static void createChoiceDialog(Activity activity){
        builder = new AlertDialog.Builder(activity);//创建对话框
        inflater = activity.getLayoutInflater();
        View layout = inflater.inflate(R.layout.dialog, null);//获取自定义布局
        builder.setView(layout);//设置对话框的布局
        dialog = builder.create();//生成最终的对话框
        dialog.show();//显示对话框

        TextView choiceImage = layout.findViewById(R.id.choiceImage);
        TextView choiceVideo = layout.findViewById(R.id.choiceVideo);
        TextView choiceAudio = layout.findViewById(R.id.choiceAudio);
        TextView cancel = layout.findViewById(R.id.cancel);

        choiceImage.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MediaUtil.pickImageFromSystem(activity);
                MediaUtil.imageFlag = true;
                dialog.dismiss();
            }
        });
        choiceVideo.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MediaUtil.pickVideoFromSystem(activity);
                dialog.dismiss();
            }
        });
        choiceAudio.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                MediaUtil.pickAudioFromSystem(activity);
                dialog.dismiss();
            }
        });

        cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dialog.dismiss();
            }
        });

    }


}
